package 算法.leetcode.labuladong.二叉树;

import 算法.leetcode.offer.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lchenglong
 * @date 2022/6/23
 */
public class 二叉树的前序遍历 {
    class Solution {

        public List<Integer> preorderTraversal(TreeNode root) {
            List<Integer> ans = new ArrayList<>();
            if (root == null) return ans;
            ans.add(root.val);
            ans.addAll(preorderTraversal(root.left));
            ans.addAll(preorderTraversal(root.right));
            return ans;
        }
    }
}
